package com.ksc.storekeeper.client.view.validation;

import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.datepicker.client.DateBox;
import com.ksc.storekeeper.client.resources.StoreKeeperResources;

public class ValidatingDateBox extends DateBox implements IsValidatingWidget<Date> {

	private static final DefaultFormat DEFAULT_FORMAT = new DefaultFormat(DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM));

	private final ValidatingHelper<Date> helper;

	public ValidatingDateBox() {
		super(DatePickerFactory.getDatePickerWithYearSelector(), null, DEFAULT_FORMAT);
		helper = new ValidatingHelper<Date>(this);
	}

	public void setRequired(boolean required) {
		helper.setRequired(required);
	}

	@Override
	public Validation validate(String date) {
		return helper.validateDate(date);
	}

	@Override
	public String getErrorMessage() {
		return helper.getErrorMessage();
	}

	@Override
	public void showInvalid() {
		helper.showInvalid();
	}

	@Override
	public void removeInvalid() {
		helper.removeInvalid();
	}

	@Override
	public Validation validateDouble(String value) {
		return null;
	}

	@Override
	public Validation validateListBox(String value) {
		return null;
	}

	@Override
	public Validation validateEmail() {
		return null;
	}

	@Override
	public void setMinLength(int length) {
	}

	@Override
	public String getText() {
		return null;
	}

	@Override
	public void setText(String arg0) {
	}

	@Override
	public Validation validate() {
		return null;
	}

	@Override
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);
		if (enabled) {
			setStyleName(StoreKeeperResources.INSTANCE.storeKeeperCss().datefield());
		} else {
			setStyleName(StoreKeeperResources.INSTANCE.storeKeeperCss().disabledDatefield());
		}
	}

	@Override
	public Validation validateDoubleWithMinLimit(Double value, Double minValue) {
		return null;
	}

	@Override
	public Validation validatePassword() {
		return null;
	}

	@Override
	public void setMaxLength(int length) {

	}

	@Override
	public Validation validatePin() {
		return null;
	}
}
